import Vue from 'vue'
import VueI18n from 'vue-i18n'

import customZhCn from './lang/zh-CN'
import customEnUs from './lang/en-US'
import customZhTW from './lang/zh-TW'
import customJa from './lang/ja'
import customKo from './lang/ko'

import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import TWLocale from 'element-ui/lib/locale/lang/zh-TW'
import jaLocale from 'element-ui/lib/locale/lang/ja'
import koLocale from 'element-ui/lib/locale/lang/ko'

Vue.use(VueI18n)

// 自动根据浏览器系统语言设置语言
// const navLang = navigator.language;


let lang = "zh";
var z = localStorage.getItem('lang');
if (z) {
    lang = z
}
Vue.config.lang = lang

Vue.locale = () => { }
const messages = {
    'zh': Object.assign(zhLocale, customZhCn),
    'en': Object.assign(enLocale, customEnUs),
    'tw': Object.assign(TWLocale, customZhTW),
    'ja': Object.assign(jaLocale, customJa),
    'ko': Object.assign(koLocale, customKo)
}
const i18n = new VueI18n({
    locale: lang,
    messages
})

export default i18n
